package com.evil.application.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.evil.application.pojo.entity.ApplicationView;
import com.evil.common.core.exception.BusinessException;
import com.evil.common.family.enums.RCodeEnum;
import org.apache.ibatis.annotations.Param;

import java.util.Collection;
import java.util.List;
import java.util.Optional;

/**
 * 应用视图配置表
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
public interface ApplicationViewMapper extends BaseMapper<ApplicationView> {

    Optional<ApplicationView> isExistById(@Param("id") Long id);

    default ApplicationView findById(Long id) {
        return this.isExistById(id).orElseThrow(() -> new BusinessException(RCodeEnum.APPLICATION_VIEW_NOT_EXIST));
    }

    Optional<ApplicationView> isExistByKey(String key);

    default ApplicationView findByKey(@Param("key") String key) {
        return this.isExistByKey(key).orElseThrow(() -> new BusinessException(RCodeEnum.APPLICATION_VIEW_NOT_EXIST));
    }

    List<ApplicationView> findByIds(@Param("ids") Collection<Long> ids);

    List<ApplicationView> findByAppIdId(@Param("applicationId") Long applicationId, @Param("applicationVersion") Integer applicationVersion);

    List<ApplicationView> findAllByAppIdId(@Param("applicationId") Long applicationId, @Param("filterDeleted") boolean filterDeleted);
}
